Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Dieser Artikel enthält ergänzende Hinweise zur Referenzdokumentation für diese API.
Die List<T> Klasse ist das generische Äquivalent der ArrayList Klasse. Sie implementiert die IList<T> generische Schnittstelle mithilfe eines Arrays, dessen Größe bei Bedarf dynamisch erhöht wird.
Sie können Elemente zu einem List<T> hinzufügen, indem Sie die Add- oder AddRange-Methoden verwenden.
Die List<T> Klasse verwendet sowohl einen Gleichheitsvergleich als auch einen Sortiervergleich.
Methoden wie Contains, IndexOf, LastIndexOfund Remove verwenden einen Gleichheitsvergleich für die Listenelemente. Der Standardmäßige Gleichheitsvergleich für den Typ
Twird wie folgt bestimmt. Wenn der TypTdie IEquatable<T> generische Schnittstelle implementiert, ist der Gleichheitsvergleich die Equals(T) Methode dieser Schnittstelle. Andernfalls lautet Object.Equals(Object)der Standardgleichgleichsvergleich.Methoden wie BinarySearch z. B. und Sort verwenden einen Sortiervergleich für die Listenelemente. Der Standard-Vergleich für Typ
Twird wie folgt bestimmt. Wenn der TypTdie IComparable<T> generische Schnittstelle implementiert, ist der Standard-Comparer die CompareTo(T) Methode dieser Schnittstelle. Andernfalls, wenn der TypTdie nichtgenerische IComparable Schnittstelle implementiert, dann ist der Standard-Comparer die CompareTo(Object) Methode dieser Schnittstelle. Wenn TypTkeine der beiden Schnittstellen implementiert, gibt es keinen Standardkomparator und ein Komparator oder Vergleichsdelegat muss explizit angegeben werden.
Es ist nicht garantiert, dass List<T> sortiert ist. Sie müssen die List<T> sortieren, bevor Sie Operationen (wie z. B. BinarySearch) durchführen, die eine Sortierung der List<T> erfordern.
Auf Elemente in dieser Auflistung kann mithilfe eines ganzzahligen Index zugegriffen werden. Indizes in dieser Auflistung sind nullbasiert.
Nur .NET Framework: Bei sehr großen List<T> Objekten können Sie die maximale Kapazität auf 2 Milliarden Elemente auf einem 64-Bit-System erhöhen, indem Sie das enabled Attribut des <gcAllowVeryLargeObjects> Konfigurationselements true in der Laufzeitumgebung festlegen.
List<T> akzeptiert null als gültiger Wert für Bezugstypen und lässt doppelte Elemente zu.
Eine unveränderliche Version der List<T> Klasse finden Sie unter ImmutableList<T>.
Leistungsüberlegungen
Bei der Entscheidung, ob die Klasse List<T> oder ArrayList verwendet werden soll, die beide eine ähnliche Funktionalität aufweisen, denken Sie daran, dass die Klasse List<T> in den meisten Fällen besser abschneidet und typsicher ist. Wenn ein Verweistyp für den Typ T der List<T> Klasse verwendet wird, ist das Verhalten der beiden Klassen identisch. Wenn jedoch ein Wertetyp für Typ T verwendet wird, müssen Sie die Implementierung und Boxing-Probleme berücksichtigen.
Wenn ein Werttyp für den Typ Tverwendet wird, generiert der Compiler eine Implementierung der List<T> Klasse speziell für diesen Werttyp. Das bedeutet, dass ein Listenelement eines List<T>-Objekts nicht geboxt werden muss, bevor das Element verwendet werden kann, und nachdem etwa 500 Listenelemente erstellt wurden, ist der Speicher, der durch nicht geboxte Listenelemente gespart wird, größer als der Speicher, der zum Generieren der Klassenimplementierung verwendet wird.
Stellen Sie sicher, dass der für den Typ T verwendete Werttyp die IEquatable<T> generische Schnittstelle implementiert. Andernfalls müssen Methoden wie z. B. Contains die Methode Object.Equals(Object) aufrufen, die das betroffene Listenelement boxed. Wenn der Wertetyp die Schnittstelle IComparable implementiert und Sie den Quellcode besitzen, implementieren Sie auch die generische Schnittstelle IComparable<T>, um zu verhindern, dass die Methoden BinarySearch und Sort Listenelemente boxen. Wenn Sie nicht über den Quellcode verfügen, übergeben Sie ein IComparer<T> Objekt an die BinarySearch und Sort methoden.
Es ist Ihr Vorteil, die typspezifische Implementierung der List<T> Klasse zu verwenden, anstatt die ArrayList Klasse zu verwenden oder eine stark typierte Wrappersammlung selbst zu schreiben. Dies liegt daran, dass Ihre Implementierung bereits die .NET-Funktion für Sie ausführen muss, und die .NET-Runtime kann gemeinsame Zwischensprachencode und -metadaten gemeinsam nutzen, die Ihre Implementierung nicht ausführen kann.
Überlegungen zu F#
Die List<T> Klasse wird selten im F#-Code verwendet. Stattdessen werden in der Regel Listen, die unveränderlich und einfach verkettete Listen sind, bevorzugt. Ein F# List bietet eine geordnete, unveränderliche Reihe von Werten und wird für die Verwendung in der funktionalen Entwicklung unterstützt. Bei Verwendung von F# wird die List<T> Klasse üblicherweise durch die ResizeArray<'T> Typabkürzung bezeichnet, um Namenskonflikte mit F#-Listen zu vermeiden.
Beispiele
Das folgende Beispiel veranschaulicht das Hinzufügen, Entfernen und Einfügen eines einfachen Geschäftsobjekts in einem List<T>.
using System;
using System.Collections.Generic;
// Simple business object. A PartId is used to identify the type of part
// but the part name can change.
public class Part : IEquatable<Part>
{
public string PartName { get; set; }
public int PartId { get; set; }
public override string ToString()
{
return "ID: " + PartId + " Name: " + PartName;
}
public override bool Equals(object obj)
{
if (obj == null) return false;
Part objAsPart = obj as Part;
if (objAsPart == null) return false;
else return Equals(objAsPart);
}
public override int GetHashCode()
{
return PartId;
}
public bool Equals(Part other)
{
if (other == null) return false;
return (this.PartId.Equals(other.PartId));
}
// Should also override == and != operators.
}
public class Example
{
public static void Main()
{
// Create a list of parts.
List<Part> parts =
[
// Add parts to the list.
new Part() { PartName = "crank arm", PartId = 1234 },
new Part() { PartName = "chain ring", PartId = 1334 },
new Part() { PartName = "regular seat", PartId = 1434 },
new Part() { PartName = "banana seat", PartId = 1444 },
new Part() { PartName = "cassette", PartId = 1534 },
new Part() { PartName = "shift lever", PartId = 1634 },
];
// Write out the parts in the list. This will call the overridden ToString method
// in the Part class.
Console.WriteLine();
foreach (Part aPart in parts)
{
Console.WriteLine(aPart);
}
// Check the list for part #1734. This calls the IEquatable.Equals method
// of the Part class, which checks the PartId for equality.
Console.WriteLine($"""
Contains("1734"): {parts.Contains(new Part { PartId = 1734, PartName = "" })}
""");
// Insert a new item at position 2.
Console.WriteLine("\nInsert(2, \"1834\")");
parts.Insert(2, new Part() { PartName = "brake lever", PartId = 1834 });
//Console.WriteLine();
foreach (Part aPart in parts)
{
Console.WriteLine(aPart);
}
Console.WriteLine($"\nParts[3]: {parts[3]}");
Console.WriteLine("\nRemove(\"1534\")");
// This will remove part 1534 even though the PartName is different,
// because the Equals method only checks PartId for equality.
parts.Remove(new Part() { PartId = 1534, PartName = "cogs" });
Console.WriteLine();
foreach (Part aPart in parts)
{
Console.WriteLine(aPart);
}
Console.WriteLine("\nRemoveAt(3)");
// This will remove the part at index 3.
parts.RemoveAt(3);
Console.WriteLine();
foreach (Part aPart in parts)
{
Console.WriteLine(aPart);
}
/*
ID: 1234 Name: crank arm
ID: 1334 Name: chain ring
ID: 1434 Name: regular seat
ID: 1444 Name: banana seat
ID: 1534 Name: cassette
ID: 1634 Name: shift lever
Contains("1734"): False
Insert(2, "1834")
ID: 1234 Name: crank arm
ID: 1334 Name: chain ring
ID: 1834 Name: brake lever
ID: 1434 Name: regular seat
ID: 1444 Name: banana seat
ID: 1534 Name: cassette
ID: 1634 Name: shift lever
Parts[3]: ID: 1434 Name: regular seat
Remove("1534")
ID: 1234 Name: crank arm
ID: 1334 Name: chain ring
ID: 1834 Name: brake lever
ID: 1434 Name: regular seat
ID: 1444 Name: banana seat
ID: 1634 Name: shift lever
RemoveAt(3)
ID: 1234 Name: crank arm
ID: 1334 Name: chain ring
ID: 1834 Name: brake lever
ID: 1444 Name: banana seat
ID: 1634 Name: shift lever
*/
}
}
' Simple business object. A PartId is used to identify the type of part
' but the part name can change.
Public Class Part
Implements IEquatable(Of Part)
Public Property PartName() As String
Get
Return m_PartName
End Get
Set(value As String)
m_PartName = value
End Set
End Property
Private m_PartName As String
Public Property PartId() As Integer
Get
Return m_PartId
End Get
Set(value As Integer)
m_PartId = value
End Set
End Property
Private m_PartId As Integer
Public Overrides Function ToString() As String
Return "ID: " & PartId & " Name: " & PartName
End Function
Public Overrides Function Equals(obj As Object) As Boolean
If obj Is Nothing Then
Return False
End If
Dim objAsPart As Part = TryCast(obj, Part)
If objAsPart Is Nothing Then
Return False
Else
Return Equals(objAsPart)
End If
End Function
Public Overrides Function GetHashCode() As Integer
Return PartId
End Function
Public Overloads Function Equals(other As Part) As Boolean _
Implements IEquatable(Of Part).Equals
If other Is Nothing Then
Return False
End If
Return (Me.PartId.Equals(other.PartId))
End Function
' Should also override == and != operators.
End Class
Public Class Example
Public Shared Sub Main()
' Create a list of parts.
Dim parts As New List(Of Part)()
' Add parts to the list.
parts.Add(New Part() With {
.PartName = "crank arm",
.PartId = 1234
})
parts.Add(New Part() With {
.PartName = "chain ring",
.PartId = 1334
})
parts.Add(New Part() With {
.PartName = "regular seat",
.PartId = 1434
})
parts.Add(New Part() With {
.PartName = "banana seat",
.PartId = 1444
})
parts.Add(New Part() With {
.PartName = "cassette",
.PartId = 1534
})
parts.Add(New Part() With {
.PartName = "shift lever",
.PartId = 1634
})
' Write out the parts in the list. This will call the overridden ToString method
' in the Part class.
Console.WriteLine()
For Each aPart As Part In parts
Console.WriteLine(aPart)
Next
' Check the list for part #1734. This calls the IEquatable.Equals method
' of the Part class, which checks the PartId for equality.
Console.WriteLine(vbLf & "Contains(""1734""): {0}", parts.Contains(New Part() With {
.PartId = 1734,
.PartName = ""
}))
' Insert a new item at position 2.
Console.WriteLine(vbLf & "Insert(2, ""1834"")")
parts.Insert(2, New Part() With {
.PartName = "brake lever",
.PartId = 1834
})
'Console.WriteLine();
For Each aPart As Part In parts
Console.WriteLine(aPart)
Next
Console.WriteLine(vbLf & "Parts[3]: {0}", parts(3))
Console.WriteLine(vbLf & "Remove(""1534"")")
' This will remove part 1534 even though the PartName is different,
' because the Equals method only checks PartId for equality.
parts.Remove(New Part() With {
.PartId = 1534,
.PartName = "cogs"
})
Console.WriteLine()
For Each aPart As Part In parts
Console.WriteLine(aPart)
Next
Console.WriteLine(vbLf & "RemoveAt(3)")
' This will remove part at index 3.
parts.RemoveAt(3)
Console.WriteLine()
For Each aPart As Part In parts
Console.WriteLine(aPart)
Next
End Sub
'
' This example code produces the following output:
' ID: 1234 Name: crank arm
' ID: 1334 Name: chain ring
' ID: 1434 Name: regular seat
' ID: 1444 Name: banana seat
' ID: 1534 Name: cassette
' ID: 1634 Name: shift lever
'
' Contains("1734"): False
'
' Insert(2, "1834")
' ID: 1234 Name: crank arm
' ID: 1334 Name: chain ring
' ID: 1834 Name: brake lever
' ID: 1434 Name: regular seat
' ID: 1444 Name: banana seat
' ID: 1534 Name: cassette
' ID: 1634 Name: shift lever
'
' Parts[3]: ID: 1434 Name: regular seat
'
' Remove("1534")
'
' ID: 1234 Name: crank arm
' ID: 1334 Name: chain ring
' ID: 1834 Name: brake lever
' ID: 1434 Name: regular seat
' ID: 1444 Name: banana seat
' ID: 1634 Name: shift lever
' '
' RemoveAt(3)
'
' ID: 1234 Name: crank arm
' ID: 1334 Name: chain ring
' ID: 1834 Name: brake lever
' ID: 1444 Name: banana seat
' ID: 1634 Name: shift lever
'
End Class
// Simple business object. A PartId is used to identify the type of part
// but the part name can change.
[<CustomEquality; NoComparison>]
type Part = { PartId : int ; mutable PartName : string } with
override this.GetHashCode() = hash this.PartId
override this.Equals(other) =
match other with
| :? Part as p -> this.PartId = p.PartId
| _ -> false
override this.ToString() = sprintf "ID: %i Name: %s" this.PartId this.PartName
[<EntryPoint>]
let main argv =
// We refer to System.Collections.Generic.List<'T> by its type
// abbreviation ResizeArray<'T> to avoid conflicts with the F# List module.
// Note: In F# code, F# linked lists are usually preferred over
// ResizeArray<'T> when an extendable collection is required.
let parts = ResizeArray<_>()
parts.Add({PartName = "crank arm" ; PartId = 1234})
parts.Add({PartName = "chain ring"; PartId = 1334 })
parts.Add({PartName = "regular seat"; PartId = 1434 })
parts.Add({PartName = "banana seat"; PartId = 1444 })
parts.Add({PartName = "cassette"; PartId = 1534 })
parts.Add({PartName = "shift lever"; PartId = 1634 })
// Write out the parts in the ResizeArray. This will call the overridden ToString method
// in the Part type
printfn ""
parts |> Seq.iter (fun p -> printfn "%O" p)
// Check the ResizeArray for part #1734. This calls the IEquatable.Equals method
// of the Part type, which checks the PartId for equality.
printfn "\nContains(\"1734\"): %b" (parts.Contains({PartId=1734; PartName=""}))
// Insert a new item at position 2.
printfn "\nInsert(2, \"1834\")"
parts.Insert(2, { PartName = "brake lever"; PartId = 1834 })
// Write out all parts
parts |> Seq.iter (fun p -> printfn "%O" p)
printfn "\nParts[3]: %O" parts.[3]
printfn "\nRemove(\"1534\")"
// This will remove part 1534 even though the PartName is different,
// because the Equals method only checks PartId for equality.
// Since Remove returns true or false, we need to ignore the result
parts.Remove({PartId=1534; PartName="cogs"}) |> ignore
// Write out all parts
printfn ""
parts |> Seq.iter (fun p -> printfn "%O" p)
printfn "\nRemoveAt(3)"
// This will remove the part at index 3.
parts.RemoveAt(3)
// Write out all parts
printfn ""
parts |> Seq.iter (fun p -> printfn "%O" p)
0 // return an integer exit code
Im folgenden Beispiel werden verschiedene Eigenschaften und Methoden der List<T> generischen Klasse des Typs Zeichenfolge veranschaulicht. (Ein Beispiel für komplexe List<T> Typen finden Sie unter der Contains Methode.)
Der parameterlose Konstruktor wird verwendet, um eine Liste von Zeichenfolgen mit der Standardkapazität zu erstellen. Die Capacity Eigenschaft wird angezeigt, und dann wird die Add Methode verwendet, um mehrere Elemente hinzuzufügen. Die Elemente werden aufgelistet, und die Capacity Eigenschaft wird zusammen mit der Count Eigenschaft erneut angezeigt, um anzuzeigen, dass die Kapazität bei Bedarf erhöht wurde.
Die Contains Methode wird verwendet, um das Vorhandensein eines Elements in der Liste zu testen, die Insert Methode wird verwendet, um ein neues Element in der Mitte der Liste einzufügen, und der Inhalt der Liste wird erneut angezeigt.
Die Standardeigenschaft Item[] (der Indexer in C#) wird verwendet, um ein Element abzurufen, die Remove Methode wird verwendet, um die erste Instanz des zuvor hinzugefügten duplizierten Elements zu entfernen, und der Inhalt wird erneut angezeigt. Die Remove Methode entfernt immer die erste Instanz, auf die sie trifft.
Die TrimExcess Methode wird verwendet, um die Kapazität an die Anzahl anzupassen, und die Eigenschaften Capacity und Count werden angezeigt. Wenn die nicht verwendete Kapazität weniger als 10 Prozent der Gesamtkapazität gewesen wäre, wäre die Größe der Liste nicht geändert worden.
Schließlich wird die Clear Methode verwendet, um alle Elemente aus der Liste zu entfernen, und die Capacity Eigenschaften Count werden angezeigt.
List<string> dinosaurs = new List<string>();
Console.WriteLine($"\nCapacity: {dinosaurs.Capacity}");
dinosaurs.Add("Tyrannosaurus");
dinosaurs.Add("Amargasaurus");
dinosaurs.Add("Mamenchisaurus");
dinosaurs.Add("Deinonychus");
dinosaurs.Add("Compsognathus");
Console.WriteLine();
foreach (string dinosaur in dinosaurs)
{
Console.WriteLine(dinosaur);
}
Console.WriteLine($"\nCapacity: {dinosaurs.Capacity}");
Console.WriteLine($"Count: {dinosaurs.Count}");
Console.WriteLine($"""\nContains("Deinonychus"): {dinosaurs.Contains("Deinonychus")}""");
Console.WriteLine("\nInsert(2, \"Compsognathus\")");
dinosaurs.Insert(2, "Compsognathus");
Console.WriteLine();
foreach (string dinosaur in dinosaurs)
{
Console.WriteLine(dinosaur);
}
// Shows accessing the list using the Item property.
Console.WriteLine($"\ndinosaurs[3]: {dinosaurs[3]}");
Console.WriteLine("\nRemove(\"Compsognathus\")");
dinosaurs.Remove("Compsognathus");
Console.WriteLine();
foreach (string dinosaur in dinosaurs)
{
Console.WriteLine(dinosaur);
}
dinosaurs.TrimExcess();
Console.WriteLine("\nTrimExcess()");
Console.WriteLine($"Capacity: {dinosaurs.Capacity}");
Console.WriteLine($"Count: {dinosaurs.Count}");
dinosaurs.Clear();
Console.WriteLine("\nClear()");
Console.WriteLine($"Capacity: {dinosaurs.Capacity}");
Console.WriteLine($"Count: {dinosaurs.Count}");
/* This code example produces the following output:
Capacity: 0
Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus
Capacity: 8
Count: 5
Contains("Deinonychus"): True
Insert(2, "Compsognathus")
Tyrannosaurus
Amargasaurus
Compsognathus
Mamenchisaurus
Deinonychus
Compsognathus
dinosaurs[3]: Mamenchisaurus
Remove("Compsognathus")
Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus
TrimExcess()
Capacity: 5
Count: 5
Clear()
Capacity: 5
Count: 0
*/
Public Class Example2
Public Shared Sub Main()
Dim dinosaurs As New List(Of String)
Console.WriteLine(vbLf & "Capacity: {0}", dinosaurs.Capacity)
dinosaurs.Add("Tyrannosaurus")
dinosaurs.Add("Amargasaurus")
dinosaurs.Add("Mamenchisaurus")
dinosaurs.Add("Deinonychus")
dinosaurs.Add("Compsognathus")
Console.WriteLine()
For Each dinosaur As String In dinosaurs
Console.WriteLine(dinosaur)
Next
Console.WriteLine(vbLf & "Capacity: {0}", dinosaurs.Capacity)
Console.WriteLine("Count: {0}", dinosaurs.Count)
Console.WriteLine(vbLf & "Contains(""Deinonychus""): {0}",
dinosaurs.Contains("Deinonychus"))
Console.WriteLine(vbLf & "Insert(2, ""Compsognathus"")")
dinosaurs.Insert(2, "Compsognathus")
Console.WriteLine()
For Each dinosaur As String In dinosaurs
Console.WriteLine(dinosaur)
Next
' Shows how to access the list using the Item property.
Console.WriteLine(vbLf & "dinosaurs(3): {0}", dinosaurs(3))
Console.WriteLine(vbLf & "Remove(""Compsognathus"")")
dinosaurs.Remove("Compsognathus")
Console.WriteLine()
For Each dinosaur As String In dinosaurs
Console.WriteLine(dinosaur)
Next
dinosaurs.TrimExcess()
Console.WriteLine(vbLf & "TrimExcess()")
Console.WriteLine("Capacity: {0}", dinosaurs.Capacity)
Console.WriteLine("Count: {0}", dinosaurs.Count)
dinosaurs.Clear()
Console.WriteLine(vbLf & "Clear()")
Console.WriteLine("Capacity: {0}", dinosaurs.Capacity)
Console.WriteLine("Count: {0}", dinosaurs.Count)
End Sub
End Class
' This code example produces the following output:
'
'Capacity: 0
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Deinonychus
'Compsognathus
'
'Capacity: 8
'Count: 5
'
'Contains("Deinonychus"): True
'
'Insert(2, "Compsognathus")
'
'Tyrannosaurus
'Amargasaurus
'Compsognathus
'Mamenchisaurus
'Deinonychus
'Compsognathus
'
'dinosaurs(3): Mamenchisaurus
'
'Remove("Compsognathus")
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Deinonychus
'Compsognathus
'
'TrimExcess()
'Capacity: 5
'Count: 5
'
'Clear()
'Capacity: 5
'Count: 0
[<EntryPoint>]
let main argv =
// We refer to System.Collections.Generic.List<'T> by its type
// abbreviation ResizeArray<'T> to avoid conflict with the List module.
// Note: In F# code, F# linked lists are usually preferred over
// ResizeArray<'T> when an extendable collection is required.
let dinosaurs = ResizeArray<_>()
// Write out the dinosaurs in the ResizeArray.
let printDinosaurs() =
printfn ""
dinosaurs |> Seq.iter (fun p -> printfn "%O" p)
printfn "\nCapacity: %i" dinosaurs.Capacity
dinosaurs.Add("Tyrannosaurus")
dinosaurs.Add("Amargasaurus")
dinosaurs.Add("Mamenchisaurus")
dinosaurs.Add("Deinonychus")
dinosaurs.Add("Compsognathus")
printDinosaurs()
printfn "\nCapacity: %i" dinosaurs.Capacity
printfn "Count: %i" dinosaurs.Count
printfn "\nContains(\"Deinonychus\"): %b" (dinosaurs.Contains("Deinonychus"))
printfn "\nInsert(2, \"Compsognathus\")"
dinosaurs.Insert(2, "Compsognathus")
printDinosaurs()
// Shows accessing the list using the Item property.
printfn "\ndinosaurs[3]: %s" dinosaurs.[3]
printfn "\nRemove(\"Compsognathus\")"
dinosaurs.Remove("Compsognathus") |> ignore
printDinosaurs()
dinosaurs.TrimExcess()
printfn "\nTrimExcess()"
printfn "Capacity: %i" dinosaurs.Capacity
printfn "Count: %i" dinosaurs.Count
dinosaurs.Clear()
printfn "\nClear()"
printfn "Capacity: %i" dinosaurs.Capacity
printfn "Count: %i" dinosaurs.Count
0 // return an integer exit code
(* This code example produces the following output:
Capacity: 0
Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus
Capacity: 8
Count: 5
Contains("Deinonychus"): true
Insert(2, "Compsognathus")
Tyrannosaurus
Amargasaurus
Compsognathus
Mamenchisaurus
Deinonychus
Compsognathus
dinosaurs[3]: Mamenchisaurus
Remove("Compsognathus")
Tyrannosaurus
Amargasaurus
Mamenchisaurus
Deinonychus
Compsognathus
TrimExcess()
Capacity: 5
Count: 5
Clear()
Capacity: 5
Count: 0
*)